home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c
- Subject: Re: What should be returned?
- Date: Wed, 24 Jan 1996 01:08:21 GMT
- Organization: Netcom
- Message-ID: <31058639.183094720@nntp.ix.netcom.com>
- References: <4dj8pv$cjd@eng_ser1.erg.cuhk.hk> <30fd5c1a.5495936@nntp.ix.netcom.com> <4dnf7d$1sa@fountain.mindlink.net> <310551bb.169614464@nntp.ix.netcom.com>
- NNTP-Posting-Host: ix-dc16-15.ix.netcom.com
- X-NETCOM-Date: Tue Jan 23 5:08:22 PM PST 1996
- X-Newsreader: Forte Agent .99c/16.141
-
- I wrote:
-
- > genew@mindlink.bc.ca (Gene Wirchenko) wrote:
- >
- > > miker3@ix.netcom.com (Mike Rubenstein) wrote:
- > > >In fact, it's even legal to have neither a return or exit():
- > >
- > > > int main(void)
- > > > {
- > > > }
- > >
- > > >This will return an undefined value to the operating environment, but
- > > >does not result in undefined behavior and will not do damage. I
- > >
- > > Returning an undefined value doesn't result in undefined
- > > bahavior? You been smokin' sumthin' funny, boy?
- > > What happens if/when the return value is interrogated as in
- > > MS-DOS's ERRORLEVEL or <other OS>'s <appropriate feature>?
- >
- > I've not been smoking anything -- I've just been reading the standard
- > in which returning an undefined value does not result in undefined
- > behavior. First, there is no requirement in the standard that the
- > operating system or shell use the returned value.
- >
- > Furthermore, the standard does not define what the operating system
- > does with any value, including 0, EXIT_SUCCESS, or EXIT_FAILURE simply
- > because that is beyond the scope of the standard.
- >
- > The standard is very clear (ISO 5.1.2.2.3):
- >
- > If the main function executes a return that specifies no
- > value, the termination status to the host environment is
- > undefined.
- >
- > It does not say the behavior is undefined, it does not say that the
- > main function shall return a value, and it does not leave undefined
- > the effect of returning no value. These are the only ways the
- > stadnard indicates undefined behavior (ISO 3.17), so returning no
- > value does not result in undefined value.
-
- Of course the last sentence should read:
-
- These are the only ways the standard indicates undefined
- behavior (ISO 3.17), so returning no value does not result in
- undefined behavior.
-
-
- Michael M Rubenstein
-